import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class TextAreaFrame extends JFrame {
	
	private JTextArea textArea1;
	private JTextArea textArea2;
	private JButton copyButton;
	
	public TextAreaFrame() {
		super("Text Area Demo");
		Box box = Box.createHorizontalBox();
		String demo = "This is demo String \n that ilusstrates copying text\nfrom one " +
		"text area to \n another textArea using a external event";
		
		textArea1 = new JTextArea(demo, 10, 15);
		textArea1.setLineWrap(true);
		box.add(new JScrollPane(textArea1));
		
		copyButton = new JButton("COPY >>>>");
		box.add(copyButton);
		copyButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				textArea2.setText(textArea1.getSelectedText());
				
			}
		});
		
		textArea2 = new JTextArea(10, 15);
		textArea2.setEditable(false);
		box.add(textArea2);
		
		add(box);
	}

}
